<template>
  <div class="content">
    <div class="p-2">
      <card-view mb-10px title="基本信息">
        <template v-slot:end>
          <el-button type="primary" @click="backAction">返回</el-button>
        </template>
        <el-form ref="basicFormRef" label-position="top" inline>
          <el-form-item label="单据编号">
            <div class="form-view-item">{{ details.codeNo }}</div>
          </el-form-item>
          <el-form-item label="检验类型">
            <div class="form-view-item">
              <dict-tag :options="check_type" :value="details.checkType" />
            </div>
          </el-form-item>
          <el-form-item label="生产组织">
            <div class="form-view-item">
              {{ details.productionOrganizationName }}
            </div>
          </el-form-item>
          <el-form-item label="生产车间">
            <div class="form-view-item">{{ details.workshopName }}</div>
          </el-form-item>
          <el-form-item label="生产人员">
            <div class="form-view-item">{{ details.productionUserName }}</div>
          </el-form-item>
          <el-form-item label="单据状态">
            <div class="form-view-item">
              <dict-tag :options="data_status" :value="details.dataStatus" />
            </div>
          </el-form-item>
          <el-form-item label="检验时间">
            <div class="form-view-item">{{ details.checkedTime }}</div>
          </el-form-item>
          <el-form-item label="质检员" prop="code">
            <div class="form-view-item">{{ details.checkUserName }}</div>
          </el-form-item>
          <el-form-item label="工序计划单号" prop="code">
            <div class="form-view-item">{{ details.planCodeNo }}</div>
          </el-form-item>
          <el-form-item label="工序任务单号" prop="code">
            <div class="form-view-item">{{ details.taskCodeNo }}</div>
          </el-form-item>
          <el-form-item label="工序" prop="code">
            <div class="form-view-item">{{ details.processName }}</div>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <div class="form-view-item">
              {{ blankAttributeDefault(details.remark) }}
            </div>
          </el-form-item>
        </el-form>
      </card-view>
      <card-view mb-10px title="产品明细">
        <el-table :data="tableList" border>
          <el-table-column label="序号" align="center">
            <template #default="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column label="产品编码" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.matterFullCode) }}
            </template>
          </el-table-column>
          <el-table-column label="产品名称" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.matterName) }}
            </template>
          </el-table-column>
          <el-table-column label="助记码" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.matterMnemonicCode) }}
            </template>
          </el-table-column>
          <el-table-column label="规格型号" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.matterSpecModel) }}
            </template>
          </el-table-column>
          <el-table-column label="表面" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.surfaceName) }}
            </template>
          </el-table-column>
          <el-table-column label="材质" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.matterMaterialQuality) }}
            </template>
          </el-table-column>
          <el-table-column label="批号" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.lotNumber) }}
            </template>
          </el-table-column>
          <el-table-column label="单轨长度(mm)" align="center" width="180">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.monorailLength) }}
            </template>
          </el-table-column>
          <el-table-column label="滑块数量" align="center" width="180">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.sliderNum) }}
            </template>
          </el-table-column>
          <el-table-column label="滑块总数量" align="center" width="180">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.sliderAllNum) }}
            </template>
          </el-table-column>
          <el-table-column
            label="导轨销售总长度(mm)"
            align="center"
            width="180"
          >
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.monorailAllLength) }}
            </template>
          </el-table-column>
          <el-table-column label="检验数量" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.checkNums) }}
            </template>
          </el-table-column>
          <el-table-column label="计量单位" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.unitName) }}
            </template>
          </el-table-column>
          <el-table-column label="辅助数量" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.assistNums) }}
            </template>
          </el-table-column>
          <el-table-column label="辅助单位" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.assistUnitName) }}
            </template>
          </el-table-column>
          <el-table-column label="合格数量" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.passNums) }}
            </template>
          </el-table-column>
          <el-table-column label="返工数量" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.reworkNums) }}
            </template>
          </el-table-column>
          <el-table-column label="让步接收数量" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.unPassNums) }}
            </template>
          </el-table-column>
          <el-table-column label="不合格原因" align="center" width="250">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.unPassReason) }}
            </template>
          </el-table-column>
          <el-table-column label="废品数量" align="center" width="150">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.wasteNums) }}
            </template>
          </el-table-column>
        </el-table>
      </card-view>
      <card-view mb-10px title="检验信息">
        <el-table :data="details.checkProcessInfoList" border>
          <el-table-column label="序号" align="center">
            <template #default="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column label="图号" align="center">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.picNum) }}
            </template>
          </el-table-column>
          <el-table-column label="检验项目" align="center">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.checkItemName) }}
            </template>
          </el-table-column>
          <el-table-column label="技术指标" align="center">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.technicalRequirement) }}
            </template>
          </el-table-column>
          <el-table-column label="检测结果" align="center">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.checkResult) }}
            </template>
          </el-table-column>
          <el-table-column label="判断结果" align="center">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.judgeResult) }}
            </template>
          </el-table-column>
          <el-table-column label="检测手段" align="center">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.checkMethod) }}
            </template>
          </el-table-column>
          <el-table-column label="检验方案" align="center">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.checkProgramme) }}
            </template>
          </el-table-column>
          <el-table-column label="检验操作要求" align="center">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.checkOperationRequirement) }}
            </template>
          </el-table-column>
          <el-table-column label="检验标准" align="center">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.checkStandardName) }}
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center">
            <template #default="scope">
              {{ blankAttributeDefault(scope.row.remark) }}
            </template>
          </el-table-column>
        </el-table>
      </card-view>
      <card-view mb-10px title="制单信息">
        <document-view :list="documentList" />
      </card-view>
    </div>
  </div>
</template>

<script setup>
import CardView from "@/components/CardView/index.vue";
import DocumentView from "@/components/DocumentView/index.vue";
import DictTag from "@/components/DictTag/index.vue";
import { blankAttributeDefault } from "@/utils/index";

import defineStore from "@/store/modules/dict";

import { getCheckProcessDetailsVOApi } from "@/api/details";
import { useRouter } from "vue-router";

const { proxy } = getCurrentInstance();
const route = useRoute();
const router = useRouter();
const { data_status, check_type } = toRefs(
  proxy?.useDict("data_status", "check_type")
);

onMounted(() => {
  getDetails(route.params.id);
});

/** 获取检验标准详情 */
const details = ref({});
const getDetails = async (id) => {
  const res = await getCheckProcessDetailsVOApi(id);
  details.value.isLastProcess = String(res.data.isLastProcess);
  details.value = res.data;
  details.value.checkType = String(details.value.checkType);
  details.value.productionOrganizationId = String(
    details.value.productionOrganizationId
  );
  details.value.dataStatus = String(details.value.dataStatus);
  documentInfoCreate(res.data);

  // 产品信息
  tableList.value = details.value.checkProcessMatterList;
  tableList.value.forEach((item) => {
    item.isOriginal = true;

    item.passNums = "0";
    item.reworkNums = "0";
    item.unPassNums = "0";
    item.wasteNums = "0";
  });
};

const tableList = ref([]);

/** 制单信息 */
const documentList = ref([]);
const documentInfoCreate = (details) => {
  let list = [];
  // 制单人
  let cteateInfo = {
    titleTop: "制单人",
    infoTop: details?.createName,
    titleBottom: "创建时间",
    infoBottom: details?.createTime,
  };
  list.push(cteateInfo);

  // 修改人
  let updateInfo = {
    titleTop: "修改人",
    infoTop: details?.updateName,
    titleBottom: "修改时间",
    infoBottom: details?.updateTime,
  };
  list.push(updateInfo);

  // 审核人
  let checkInfo = {
    titleTop: "审核人",
    infoTop: details?.checkName,
    titleBottom: "审核时间",
    infoBottom: details?.checkTime,
  };
  list.push(checkInfo);
  documentList.value = list;
};
documentInfoCreate();

/** 返回 */
const backAction = () => {
  router.go(-1);
};
</script>

<style lang="scss" scoped></style>
